
#ifndef __USRAPP_H_INCLUDED__
#define __USRAPP_H_INCLUDED__

#include "vsfvm.h"
#include "lexer/dart/vsfvm_lexer_dart.h"
#include "vsfvm_compiler.h"
#include "vsfvm_snapshot.h"

#include "std/vsfvm_ext_std.h"
#include "vsf/vsfvm_ext_vsf.h"

struct usrapp_t
{
	struct
	{
		struct vsf_usart_stream_t uart_stream;
		struct vsf_fifostream_t stream_tx;
		struct vsf_fifostream_t stream_rx;
		uint8_t txbuff[16 * 1024];
		uint8_t rxbuff[16 * 1024];

		char linebuf[1024];
		uint32_t linepos;
	} debug;

	struct
	{
		struct vsfsm_thread_t thread;
		struct vsfsm_t sm;
		uint8_t stack[4096];
	} wifi;

	struct
	{
		struct
		{
			struct vsfvmc_t vmc;
			struct vsfvmc_lexer_list_t dart;
		} compiler;
		struct
		{
			struct vsfvm_t vm;
			struct vsfvm_script_t script;
		} runtime;
		struct vsfvmc_snapshot_t snapshot;

		uint32_t token[4 * 1024];
		uint32_t bytecode_pos;
		bool wait_prompt;
	} vsfvm;
};

extern struct usrapp_t usrapp;

bool usrapp_cansleep(struct usrapp_t *app);
void usrapp_srt_init(struct usrapp_t *app);
void usrapp_srt_poll(struct usrapp_t *app);
void usrapp_nrt_init(struct usrapp_t *app);
void usrapp_nrt_poll(struct usrapp_t *app);

#endif		// __USRAPP_H_INCLUDED__
